package cn.iocoder.yudao.module.digital.controller.app.cardkeysecret;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.module.digital.controller.app.cardkeysecret.vo.AppCardkeySecretRespVO;
import cn.iocoder.yudao.module.digital.dal.dataobject.cardkeysecret.CardkeySecretDO;
import cn.iocoder.yudao.module.digital.service.cardkeysecret.CardkeySecretService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Tag(name = "用户 App - 卡密密钥")
@RestController
@RequestMapping("/digital/cardkey-secret")
@Validated
public class AppCardkeySecretController {
    @Resource
    private CardkeySecretService cardkeySecretService;

    @Deprecated
    @GetMapping("/get-by-order-no")
    @Operation(summary = "查询卡密密钥-通过订单号")
    @Parameter(name = "orderNo", description = "订单流水号", required = true, example = "1024")
    @PreAuthenticated
    public CommonResult<List<AppCardkeySecretRespVO>> getCardkeySecretByOrderNo(@RequestParam("orderNo") String orderNo) {
        final Long loginUserId = getLoginUserId();
        final List<CardkeySecretDO> secretDOList = cardkeySecretService.getCardKeySecretByOrderNo(loginUserId, orderNo);
        return success(BeanUtils.toBean(secretDOList, AppCardkeySecretRespVO.class));
    }

}